package com.icinfo.cloud.provider.punish.ucase.punishexecute.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.annotation.CaseChangeReportData;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.approval.constant.AuditStatusConstant;
import com.icinfo.cloud.provider.punish.common.documentoperate.dto.StageDocCommonOperateSaveDto;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentRecordStatusEnum;
import com.icinfo.cloud.provider.punish.common.documentoperate.service.IStageDocCommonOperateService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseAttachmentInfoQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseAttachmentInfoSaveDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDocumentRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseMainDetailAuxiliaryInfoRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseAppendixRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseDocumentRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainDetailAuxiliaryInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainDetailInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseAttachmentInfoVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseHandlePersonRecordVo;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseMainInfoVo;
import com.icinfo.cloud.provider.punish.ucase.payment.dto.CasePaymentMainRecordStatusUpdateDto;
import com.icinfo.cloud.provider.punish.ucase.payment.enums.PayStatusEnum;
import com.icinfo.cloud.provider.punish.ucase.payment.service.ICasePaymentMainRecordService;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.dto.CasePunishActionDto;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.dto.EnforceExecuteApplyInfoQueryDto;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.dto.EnforceExecuteApplyInfoSaveDto;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.service.ICaseExecuteService;
import com.icinfo.cloud.provider.punish.ucase.punishexecute.vo.EnforceExecuteApplyInfoVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.dto.ExecuteFinishInfoQueryDto;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.CaseExecuteInfoVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.ExecuteConditionDocContentAutoVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.ExecuteConditionDocContentVo;
import com.icinfo.cloud.provider.punish.ucase.punishinform.vo.ExecuteFinishInfoVo;
import com.icinfo.cloud.workflow.common.annotation.WorkFlowRollAnnotation;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * 描述：处罚执行服务实现类
 *
 * @author xiangyuyu
 * @date 2022/4/9 10:58
 */
@Service
@Slf4j
public class CaseExecuteServiceImpl implements ICaseExecuteService {
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;
    @Resource
    private ICaseMainDetailInfoService caseMainDetailInfoService;
    @Resource
    private CaseAppendixRecordMapper caseAppendixRecordMapper;
    @Resource
    private ICaseAppendixRecordService caseAppendixRecordService;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private ICaseHandlePersonRecordService caseHandlePersonRecordService;
    @Resource
    private IStageDocCommonOperateService stageDocCommonOperateService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private ICaseMainDetailAuxiliaryInfoService caseMainDetailAuxiliaryInfoService;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Resource
    private ICasePaymentMainRecordService casePaymentMainRecordService;

    @Resource
    private ICaseMainDetailSimpleInfoService caseMainDetailSimpleInfoService;

    /**
     * 【V1.1.0】描述：保存强制执行申请信息
     *
     * @param saveDto {@link EnforceExecuteApplyInfoSaveDto}
     * @return {@link Result <String>} 保存结果
     * @author xiangyuyu
     * @date 2022-04-09 11:57
     */
    @Override
    public Result<String> saveEnforceExecuteApplyInfo(EnforceExecuteApplyInfoSaveDto saveDto) {
        String caseId = saveDto.getCaseId();
        String documentCatalogCode = saveDto.getDocumentCatalogCode();
        if (ObjectUtils.isEmpty(caseId)) {
            return Result.error("未指定案件id");
        }
        //校验案件信息
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        if (ObjectUtils.isEmpty(caseMainInfo)) {
            return Result.error("未匹配到案件信息");
        }
        CaseMainDetailInfo caseMainDetailInfo = new CaseMainDetailInfo();
        BeanUtils.copyProperties(saveDto, caseMainDetailInfo);
        //非诉审核类型、案件涉及、管辖依据 根据code获取name赋值
        caseMainDetailInfo.setAdrApprovalTypeName(AdrApprovalTypeEnum.getValueByCode(caseMainDetailInfo.getAdrApprovalTypeId()));
        caseMainDetailInfo.setCaseInvolveName(CaseInvolveEnum.getValueByCode(caseMainDetailInfo.getCaseInvolveId()));
        caseMainDetailInfo.setJurisdictionBasisName(JurisdictionBasisEnum.getValueByCode(caseMainDetailInfo.getJurisdictionBasisId()));
        caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
        //保存附件
        //经营者或法人身份证件文件列表
        List<CaseAttachmentInfoSaveDto> userCardFileList = saveDto.getUserCardFileList();
        if (ObjectUtils.isEmpty(userCardFileList) || userCardFileList.size() == 0) {
            return Result.error("未指定经营者或法人身份证件");
        }
        //营业执照或社会信用代码证书文件列表
        // CasePartiesDetailInfoVo casePartiesInfo = casePartiesRecordService.getCasePartiesDetailInfo(caseId);
        List<CaseAttachmentInfoSaveDto> businessLicenceCertFileList = new ArrayList<>();
//        if (PartyTypeEnum.LEGAL.getCode().equals(casePartiesInfo.getPartyType())) {
//            if (ObjectUtils.isEmpty(businessLicenceCertFileList) || businessLicenceCertFileList.size() == 0) {
//                return Result.error("未指定营业执照或社会信用代码证书");
//            }
//        }
        if (null != saveDto.getBusinessLicenceCertFileList() && saveDto.getBusinessLicenceCertFileList().size() > 0) {
            businessLicenceCertFileList = saveDto.getBusinessLicenceCertFileList();
        }
        UserDTO userInfo = UserUtil.getUserInfo();
        List<CaseAttachmentInfoSaveDto> caseAttachmentInfoList = new ArrayList<>();
        caseAttachmentInfoList.addAll(userCardFileList);
        caseAttachmentInfoList.addAll(businessLicenceCertFileList);
        if (!ObjectUtils.isEmpty(saveDto.getOtherFileList())) {
            caseAttachmentInfoList.addAll(saveDto.getOtherFileList());
        }
        caseAttachmentInfoList.forEach(e -> {
            CaseAppendixRecord caseAppendixRecord = new CaseAppendixRecord();
            String attachmentId = e.getId();
            if (ObjectUtils.isEmpty(attachmentId)) {
                BeanUtils.copyProperties(e, caseAppendixRecord);
                caseAppendixRecord.setId(BaseUtil.createUid());
                caseAppendixRecord.setCaseId(caseId);
                caseAppendixRecord.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
                caseAppendixRecord.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
                caseAppendixRecord.setCaseLinkCode(caseMainInfo.getCaseCurrentLinkCode());
                caseAppendixRecord.setCaseLinkName(caseMainInfo.getCaseCurrentLinkName());
                caseAppendixRecord.setDocumentCatalogCode(documentCatalogCode);
                if (!ObjectUtils.isEmpty(userInfo)) {
                    caseAppendixRecord.setUploadUserId(userInfo.getUserId() + "");
                    caseAppendixRecord.setUploadUserName(userInfo.getRealName());
                }
                caseAppendixRecord.setUploadTime(LocalDateTime.now());
                String appendixTypeId = caseAppendixRecord.getAppendixTypeId();
                if (ObjectUtils.isEmpty(appendixTypeId)) {
                    throw new BusinessException("未指定附件类型id【" + caseAppendixRecord.getAppendixName() + "】");
                }
                String appendixUrl = caseAppendixRecord.getAppendixUrl();
                if (ObjectUtils.isEmpty(appendixUrl)) {
                    throw new BusinessException("未指定附件地址【" + caseAppendixRecord.getAppendixName() + "】");
                }
                caseAppendixRecordMapper.insertSelective(caseAppendixRecord);
            }
        });
        return Result.success(Constant.STRING_SAVE_SUCCESS);
    }

    /**
     * 【V1.1.0】描述：获取强制执行申请信息
     *
     * @param queryDto {@link EnforceExecuteApplyInfoQueryDto}
     * @return {@link EnforceExecuteApplyInfoVo} 强制执行申请信息
     * @author xiangyuyu
     * @date 2022-04-09 11:57
     */
    @Override
    public EnforceExecuteApplyInfoVo getEnforceExecuteApplyInfo(EnforceExecuteApplyInfoQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        if (ObjectUtils.isEmpty(caseId)) {
            throw new BusinessException("未指定案件id");
        }
        EnforceExecuteApplyInfoVo vo = new EnforceExecuteApplyInfoVo();
        //获取案件宽表信息
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoService.getCaseMainDetailByCaseId(caseId);
        CaseAttachmentInfoQueryDto q = new CaseAttachmentInfoQueryDto();
        q.setCaseId(caseId);
        q.setAttachmentTypeId(AttachmentTypeEnum.USER_CARD.getCode());
        q.setDocumentCatalogCode(queryDto.getDocumentCatalogCode());
        List<String> notShowInOtherFileList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(caseMainDetailInfo)) {
            BeanUtils.copyProperties(caseMainDetailInfo, vo);
            //获取附件信息
            List<CaseAttachmentInfoVo> userCardFileList = caseAppendixRecordService.getCaseAttachmentInfoList(q);
            userCardFileList.forEach(e -> notShowInOtherFileList.add(e.getId()));
            vo.setUserCardFileList(userCardFileList);
            q.setAttachmentTypeId(AttachmentTypeEnum.BUSINESS_LICENCE_CERT.getCode());
            List<CaseAttachmentInfoVo> businessLicenceCertFileList = caseAppendixRecordService.getCaseAttachmentInfoList(q);
            businessLicenceCertFileList.forEach(e -> notShowInOtherFileList.add(e.getId()));
            vo.setBusinessLicenceCertFileList(businessLicenceCertFileList);
            q.setAttachmentTypeId("");
            List<CaseAttachmentInfoVo> otherFileListTmp = caseAppendixRecordService.getCaseAttachmentInfoList(q);
            List<CaseAttachmentInfoVo> otherFileList = new ArrayList<>();
            otherFileListTmp.forEach(e -> {
                if (!notShowInOtherFileList.contains(e.getId())) {
                    otherFileList.add(e);
                }
            });
            vo.setOtherFileList(otherFileList);
            return vo;
        } else {
            throw new BusinessException("未找到案件信息-caseId:" + caseId);
        }
    }


    @Override
    @WorkFlowRollAnnotation
    @CaseChangeReportData
    public Map<String, Object> savePunishExecuteInfo(CasePunishActionDto casePunishActionDto) {
        String caseId = casePunishActionDto.getCaseId();
        //获取案件信息
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        if(caseMainInfoService.validateCaseIsInNotDealStatus(caseMainInfo,null)){
            throw new BusinessException("当前案件状态不允许进行该操作");
        }
        String partyId = casePunishActionDto.getPartyId();
        String isShowPartiesSelector = caseMainInfoService.validateIsShowPartiesSelector(caseMainInfo,null);
        Map<String, String> map = casePartiesRecordService.getCasePartyIdNameInfo(caseId);
        if (YesOrNoEnum.YES.getCode().equals(isShowPartiesSelector)
                && ObjectUtils.isEmpty(partyId)) {
            throw new BusinessException("多当事人分别处罚时请指定当事人id");
        }

        String allPartyIds = map.get("partyId");
        if(ObjectUtils.isEmpty(partyId)){
            partyId  = allPartyIds;
        }
        String partyName = map.get("partyName");
        //获取该当事人的名称
        String[] idArr = allPartyIds.split(",");
        String[] nameArr = partyName.split(",");
        for (int i = 0; i < idArr.length; i++) {
            if(partyId.equals(idArr[i])){
                partyName = nameArr[i];
            }
        }

        String handleType = caseMainInfo.getHandleType();
        String partiesReasonType = caseMainInfo.getCasePartiesReasonType();

        int upr;
        Example example;
        LocalDate executeFinishDate = LocalDate.parse(casePunishActionDto.getPunishDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        if (HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(partiesReasonType)) {
            example = new Example(CaseMainDetailAuxiliaryInfo.class);
            Example.Criteria criteria = example.createCriteria();
            criteria.andEqualTo("caseId", caseId);
            criteria.andEqualTo("partyId", partyId);
            CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfoMapper.selectByExample(example).get(0);
            caseMainDetailAuxiliaryInfo.setExecuteFinishDate(executeFinishDate);
            // 存为中文
            caseMainDetailAuxiliaryInfo.setExecuteWay(casePunishActionDto.getPunishType());
            if (AuditStatusConstant.CONSCIOUS_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                caseMainDetailAuxiliaryInfo.setExecuteWay("自觉履行");
            }
            if (AuditStatusConstant.ENFORCE_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                caseMainDetailAuxiliaryInfo.setExecuteWay("强制执行");
            }
            caseMainDetailAuxiliaryInfo.setExecuteConditionDesc(casePunishActionDto.getPunishActionDesc());
            upr = caseMainDetailAuxiliaryInfoMapper.updateByExample(caseMainDetailAuxiliaryInfo, example);
            boolean isAllBranchFlowExecuteFinish = dealAfterAllBranchFlowExecuteFinish(caseId);
            log.info(isAllBranchFlowExecuteFinish?"all branch flow execute finish":"exists not execute finish branch");
        } else {
            example = new Example(CaseMainDetailInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId);
            CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByExample(example).get(0);
            caseMainDetailInfo.setExecuteFinishDate(executeFinishDate);
            // 存为中文
            caseMainDetailInfo.setExecuteWay(casePunishActionDto.getPunishType());
            if (AuditStatusConstant.CONSCIOUS_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                caseMainDetailInfo.setExecuteWay("自觉履行");
            }
            if (AuditStatusConstant.ENFORCE_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                caseMainDetailInfo.setExecuteWay("强制执行");
            }
            caseMainDetailInfo.setExecuteConditionDesc(casePunishActionDto.getPunishActionDesc());
            upr = caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
            try {
                //单当事人单案由 更新补充表数据
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
                caseMainDetailAuxiliaryInfo.setCaseId(caseId);
                caseMainDetailAuxiliaryInfo.setExecuteFinishDate(executeFinishDate);
                // 存为中文
                caseMainDetailAuxiliaryInfo.setExecuteWay(casePunishActionDto.getPunishType());
                if (AuditStatusConstant.CONSCIOUS_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                    caseMainDetailAuxiliaryInfo.setExecuteWay("自觉履行");
                }
                if (AuditStatusConstant.ENFORCE_EXECUTE.equals(casePunishActionDto.getPunishType())) {
                    caseMainDetailAuxiliaryInfo.setExecuteWay("强制执行");
                }
                caseMainDetailAuxiliaryInfo.setExecuteConditionDesc(casePunishActionDto.getPunishActionDesc());
                caseMainDetailAuxiliaryInfoService.editSpecialParamSingle(caseMainDetailAuxiliaryInfo);
            }catch (Exception e){
                e.printStackTrace();
            }
        }

        String documentCatalogCode = "ZXQKHCJL29F3F";
        // 行政处理-执行情况核查记录文书编码为“ZXQKHCJL29F4F”
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            documentCatalogCode = "ZXQKHCJL29F4F";
        }
        //保存附件
        //缴款凭证文件列表
        List<CaseAttachmentInfoSaveDto> paymentProofFileList = casePunishActionDto.getPaymentProofFileList();
        /*if (ObjectUtils.isEmpty(paymentProofFileList) || paymentProofFileList.size() == 0) {
            throw new BusinessException("未指定缴款凭证");
        }*/
        //现场核查记录文件列表
        List<CaseAttachmentInfoSaveDto> realPlaceCheckRecordFileList = casePunishActionDto.getRealPlaceCheckRecordFileList();

        UserDTO userInfo = UserUtil.getUserInfo();
        List<CaseAttachmentInfoSaveDto> caseAttachmentInfoList = new ArrayList<>();
        if(!ObjectUtils.isEmpty(paymentProofFileList)) {
            caseAttachmentInfoList.addAll(paymentProofFileList);
        }
        if (!ObjectUtils.isEmpty(realPlaceCheckRecordFileList)) {
            caseAttachmentInfoList.addAll(realPlaceCheckRecordFileList);
        }
        if (!ObjectUtils.isEmpty(casePunishActionDto.getOtherFileList())) {
            caseAttachmentInfoList.addAll(casePunishActionDto.getOtherFileList());
        }
        String finalPartyId = partyId;
        String finalDocumentCatalogCode = documentCatalogCode;
        caseAttachmentInfoList.forEach(e -> {
            CaseAppendixRecord caseAppendixRecord = new CaseAppendixRecord();
            String attachmentId = e.getId();
            if (ObjectUtils.isEmpty(attachmentId)) {
                BeanUtils.copyProperties(e, caseAppendixRecord);
                caseAppendixRecord.setId(BaseUtil.createUid());
                caseAppendixRecord.setCaseId(caseId);
                caseAppendixRecord.setCaseStageName(caseMainInfo.getCaseCurrentStageName());
                caseAppendixRecord.setCaseStageCode(caseMainInfo.getCaseCurrentStageCode());
                caseAppendixRecord.setCaseLinkCode(caseMainInfo.getCaseCurrentLinkCode());
                caseAppendixRecord.setCaseLinkName(caseMainInfo.getCaseCurrentLinkName());
                caseAppendixRecord.setDocumentCatalogCode(finalDocumentCatalogCode);
                if (!ObjectUtils.isEmpty(userInfo)) {
                    caseAppendixRecord.setUploadUserId(userInfo.getUserId() + "");
                    caseAppendixRecord.setUploadUserName(userInfo.getRealName());
                }
                caseAppendixRecord.setUploadTime(LocalDateTime.now());
                String appendixTypeId = caseAppendixRecord.getAppendixTypeId();
                if (ObjectUtils.isEmpty(appendixTypeId)) {
                    throw new BusinessException("未指定附件类型id【" + caseAppendixRecord.getAppendixName() + "】");
                }
                String appendixUrl = caseAppendixRecord.getAppendixUrl();
                if (ObjectUtils.isEmpty(appendixUrl)) {
                    throw new BusinessException("未指定附件地址【" + caseAppendixRecord.getAppendixName() + "】");
                }
                caseAppendixRecord.setPartyId(finalPartyId);
                caseAppendixRecordMapper.insertSelective(caseAppendixRecord);
            }
        });
        //执行情况记录生成
        generateExecuteConditionRecord(caseId, realPlaceCheckRecordFileList, paymentProofFileList,finalPartyId,partyName);
        //更新缴款单状态为线下已缴款
        CasePaymentMainRecordStatusUpdateDto updateDto =
                new CasePaymentMainRecordStatusUpdateDto(caseId, partyId, PayStatusEnum.OFFLINE_PAID.getCode());
        casePaymentMainRecordService.updateCasePaymentMainRecordStatus(updateDto);

        Map<String, Object> result = new HashMap<>(8);
        if (upr == 1) {
            if (!caseMainInfoService.checkCaseIsPartiesPartPunish(null,caseMainInfo)){
                partyId = null;
            }
            //result = executeFlowRoll(caseId,partyId,"ZXQKHCJL29F3F");
            result.put("success", "true");
            result.put("msg", "成功！");
        } else {
            log.info("savePunishExecuteInfo savePunishExecuteInfo error");
            throw new BusinessException("保存处罚执行信息时出现异常");
        }
        return result;
    }

    /**
     * 描述：所有分支流程都已执行完成时后续操作
     *
     * @param caseId 案件id
     * @return boolean 所有分支流程都已执行完成 (true-是/false-否)
     * @author xiangyuyu
     * @date 2022-06-15 16:00
     */
    @Override
    public boolean dealAfterAllBranchFlowExecuteFinish(String caseId) {
        Example query = new Example(CaseMainDetailAuxiliaryInfo.class);
        query.setOrderByClause(" execute_finish_date desc ");
        Example.Criteria c = query.createCriteria();
        c.andEqualTo("caseId", caseId);
        List<CaseMainDetailAuxiliaryInfo> branchFlowInfoList = caseMainDetailAuxiliaryInfoMapper.selectByExample(query);
        boolean isAllBranchFlowExecuteFinish = true;
        for (CaseMainDetailAuxiliaryInfo e : branchFlowInfoList) {
            if (ObjectUtils.isEmpty(e.getExecuteFinishDate())) {
                isAllBranchFlowExecuteFinish = false;
            }
        }
        if (isAllBranchFlowExecuteFinish) {
            //更新宽表的案件执行完成日期
            Example update = new Example(CaseMainDetailInfo.class);
            update.createCriteria().andEqualTo("caseId", caseId);
            CaseMainDetailInfo caseMainDetailInfo = new CaseMainDetailInfo();
            caseMainDetailInfo.setCaseId(caseId);
            caseMainDetailInfo.setExecuteFinishDate(branchFlowInfoList.get(Constant.INTEGER_0).getExecuteFinishDate());
            caseMainDetailInfoMapper.updateByPrimaryKeySelective(caseMainDetailInfo);
        }
        return isAllBranchFlowExecuteFinish;
    }

    @Override
    public CaseExecuteInfoVo getExecuteInfoByCaseId(String caseId) {
        if (Objects.isNull(caseId)){
            throw new BusinessException("案件id不能为空");
        }
        CaseExecuteInfoVo vo = new CaseExecuteInfoVo();
        //获取执行情况
        CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest();
        request.setCaseId(caseId);
        CaseMainDetailSimpleInfo caseMainDetailSimpleInfo = caseMainDetailSimpleInfoService.getCaseMainDetailSimpleInfo(caseId);
        if (Objects.isNull(caseMainDetailSimpleInfo)) {
            //无执行情况
            return vo;
        }
        vo.setExecuteDate(caseMainDetailSimpleInfo.getExecuteFinishDate());
        vo.setExecuteWay(caseMainDetailSimpleInfo.getExecuteWay());
        vo.setExecuteDesc(caseMainDetailSimpleInfo.getExecuteConditionDesc());
        //得到案件附件
        CaseAttachmentInfoQueryDto dto = new CaseAttachmentInfoQueryDto();
        dto.setCaseId(caseId);
        //执行情况附件
        dto.setAttachmentTypeId(AttachmentTypeEnum.SIMPLE_CASE_ATTACHMENT_01.getCode());
        List<CaseAttachmentInfoVo> caseAttachmentList = caseAppendixRecordService.getCaseAttachmentList(dto);
        vo.setCaseAttachmentList(caseAttachmentList);
        return vo;
    }


    /**
     * 描述：生成执行情况核查记录
     *
     * @param caseId                       案件id
     * @param realPlaceCheckRecordFileList 现场核查记录文件列表
     * @param paymentProofFileList         缴款凭证文件列表
     * @param partyId                      当事人id
     * @param partyName                    当事人名称
     * @author xiangyuyu
     * @date 2022-04-25 15:11
     */
    private void generateExecuteConditionRecord(String caseId, List<CaseAttachmentInfoSaveDto> realPlaceCheckRecordFileList, List<CaseAttachmentInfoSaveDto> paymentProofFileList,String partyId,String partyName) {
        StageDocCommonOperateSaveDto saveDto = new StageDocCommonOperateSaveDto();
        HashMap<String, Object> dataMap = new HashMap<>();
        //获取案件信息
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        String handleType = caseMainInfo.getHandleType();
        String partiesReasonType = caseMainInfo.getCasePartiesReasonType();
        /*
        不同处置类型和案件案由类型，取数分析：
        1.单当事人单案由 宽表
        2.单当事人多案由 宽表
        3.多当事人单案由
            -合并处罚 宽表
            -分别处罚 补充表
         */
        dataMap.put("ZXQKJL_DSR", partyName);

        if(HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)
                && PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(partiesReasonType)){
            //获取补充表数据
            CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest(caseId,partyId);
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfoList = caseMainDetailAuxiliaryInfoService.getCaseMainDetailAuxiliaryInfo(request);
            if(ObjectUtils.isEmpty(caseMainDetailAuxiliaryInfoList) || caseMainDetailAuxiliaryInfoList.size() == 0 ){
                throw new BusinessException("未匹配到案件补充表详情-caseId：" + caseId+"，partyId："+partyId);
            }

            CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfoList.get(Constant.INTEGER_0);
            LocalDate executeFinishDate = caseMainDetailAuxiliaryInfo.getExecuteFinishDate();
            String tmp = executeFinishDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日"));
            //执行完成日期
            dataMap.put("ZXQKJL_ZXWCRQ", tmp);

            //执行情况描述
            String executeConditionDesc = caseMainDetailAuxiliaryInfo.getExecuteConditionDesc();
            dataMap.put("ZXQKJL_ZXJCQK", executeConditionDesc);
            //执行方式
            String executeWay = caseMainDetailAuxiliaryInfo.getExecuteWay();
            dataMap.put("ZXQKJL_ZXFS", executeWay);

            String documentNumber = caseMainDetailAuxiliaryInfo.getPunishDocumentNumber();
            dataMap.put("ZXQKJL_BZ",documentNumber);
        } else {
            //获取宽表信息
            CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoService.getCaseMainDetailByCaseId(caseId);
            if (ObjectUtils.isEmpty(caseMainDetailInfo)) {
                throw new BusinessException("未匹配到案件详情-caseId：" + caseId);
            }
            LocalDate executeFinishDate = caseMainDetailInfo.getExecuteFinishDate();
            String tmp = executeFinishDate.format(DateTimeFormatter.ofPattern("yyyy年M月d日"));
            //执行完成日期
            dataMap.put("ZXQKJL_ZXWCRQ", tmp);

            //执行情况描述
            String executeConditionDesc = caseMainDetailInfo.getExecuteConditionDesc();
            dataMap.put("ZXQKJL_ZXJCQK", executeConditionDesc);
            //执行方式
            String executeWay = caseMainDetailInfo.getExecuteWay();
            dataMap.put("ZXQKJL_ZXFS", executeWay);

            String documentNumber = caseMainDetailInfo.getPunishDocumentNumber();
            dataMap.put("ZXQKJL_BZ",documentNumber);
        }

        //缴款凭证	ZXQKJL_JKPZ
        List<String> urlList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(paymentProofFileList) && paymentProofFileList.size() > 0) {
            for (CaseAttachmentInfoSaveDto e : paymentProofFileList) {
                urlList.add(e.getAppendixUrl());
            }
        }
        /*dataMap.put("ZXQKJL_JKPZ", urlList);*/

        List<Object> jkpzList = new ArrayList<>();
        urlList.forEach(e->{
            Map<String,String> jkpzMap = new HashMap<>(20);
            jkpzMap.put("ZXQKJL_JKPZ",e);
            jkpzList.add(jkpzMap);
        });
        dataMap.put("ZXQKJL_JKPZ_LIST",jkpzList);

        //现场核查记录	ZXQKJL_XCHCJL
        urlList = new ArrayList<>();
        if (!ObjectUtils.isEmpty(realPlaceCheckRecordFileList) && realPlaceCheckRecordFileList.size() > 0) {
            for (CaseAttachmentInfoSaveDto e : realPlaceCheckRecordFileList) {
                urlList.add(e.getAppendixUrl());
            }
        }
        List<Object> xchcjlList = new ArrayList<>();
        urlList.forEach(e->{
            Map<String,String> xchcjlMap = new HashMap<>(20);
            xchcjlMap.put("ZXQKJL_XCHCJL",e);
            xchcjlList.add(xchcjlMap);
        });
        dataMap.put("ZXQKJL_XCHCJL_LIST",xchcjlList);
        /*dataMap.put("ZXQKJL_XCHCJL", urlList);*/
        //获取办案人员
        List<CaseHandlePersonRecordVo> caseHandlePersonRecordList = caseHandlePersonRecordService.getCaseHandlePersonRecordListByCaseId(caseId);
        String mainHandlerName = "";
        String assistHandlerName = "";

        String mainHandlerCert = "";
        String assistHandlerCert = "";
        for (CaseHandlePersonRecordVo handler : caseHandlePersonRecordList) {
            String handlePersonType = handler.getHandlePersonType();
            if (Constant.STRING_1.equals(handlePersonType)) {
                //主办
                mainHandlerName = handler.getHandlePersonName();
                mainHandlerCert = handler.getLawEnforcementCert();
            } else {
                //协办
                assistHandlerName = handler.getHandlePersonName();
                assistHandlerCert = handler.getLawEnforcementCert();
            }
            if (!ObjectUtils.isEmpty(mainHandlerName) && !ObjectUtils.isEmpty(assistHandlerName)) {
                break;
            }
        }
        dataMap.put("ZXQKJL_ZBRYXM", mainHandlerName);
        dataMap.put("ZXQKJL_ZBRYZFZH", mainHandlerCert);

        dataMap.put("ZXQKJL_XBRYXM", assistHandlerName);
        dataMap.put("ZXQKJL_XBRYZFZH", assistHandlerCert);
        //处罚决定书文号 CFJDSWH
        String kindCode = Constant.STRING_KIND_CODE_CFJDS;
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            kindCode = Constant.STRING_KIND_CODE_CLJDS;
        }
        CaseDocumentRecordDto documentRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, kindCode);
        if (ObjectUtils.isEmpty(documentRecord)) {
            throw new BusinessException("未匹配到处罚决定书信息-caseId:" + caseId + ",kindCode:" + kindCode);
        }

        String documentCatalogCode = "ZXQKHCJL29F3F";
        // 行政处理-执行情况核查记录文书编码为“ZXQKHCJL29F4F”
        if (Constant.STRING_2.equals(caseMainDetailInfoMapper.getHandleConclusionByCaseId(caseId))) {
            documentCatalogCode = "ZXQKHCJL29F4F";
        }
        saveDto.setCaseId(caseId);
        saveDto.setDocumentCatalogCode(documentCatalogCode);
        saveDto.setDataMap(dataMap);
        saveDto.setIsUpdateRelationTable(YesOrNoEnum.NO.getCode());
        saveDto.setPartyId(partyId);
        stageDocCommonOperateService.saveDocInfo(saveDto);
    }

    /**
     * 【V1.1.0】描述：获取执行完成情况信息
     *
     * @param queryDto {@link ExecuteFinishInfoQueryDto}
     * @return {@link Result< ExecuteFinishInfoVo >} 执行完成情况信息
     * @author xiangyuyu
     * @date 2022-04-09 11:57
     */
    @Override
    public ExecuteFinishInfoVo getExecuteFinishInfo(ExecuteFinishInfoQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        //获取案件详情记录表信息
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoService.getCaseMainDetailByCaseId(caseId);
        LocalDate executeFinishDate = caseMainDetailInfo.getExecuteFinishDate();
        if (ObjectUtils.isEmpty(executeFinishDate)) {
            throw new BusinessException("该案件未执行完成");
        }

        ExecuteFinishInfoVo vo = new ExecuteFinishInfoVo();
        BeanUtils.copyProperties(caseMainDetailInfo, vo);
        vo.setPunishDate(caseMainDetailInfo.getExecuteFinishDate());
        vo.setPunishType(caseMainDetailInfo.getExecuteWay());
        vo.setPunishActionDesc(caseMainDetailInfo.getExecuteConditionDesc());

        //获取附件信息
        CaseAttachmentInfoQueryDto queryAttach = new CaseAttachmentInfoQueryDto();
        queryAttach.setCaseId(caseId);
        //不管是自动还是非自动执行完成，最多有且只会有1条执行记录
        CaseDocumentRecord documentRecord = caseDocumentRecordService.getCaseDocumentRecordByKindCode(caseId, "ZXQKHCJL");
        //获取文书目录编码
        if (ObjectUtils.isEmpty(documentRecord)) {
            throw new BusinessException("未匹配到执行情况记录-caseId:" + caseId);
        }
        String documentCatalogCode = documentRecord.getDocumentCatalogCode();


        List<String> notShowInOtherFileList = new ArrayList<>();
        queryAttach.setCaseId(caseId);
        queryAttach.setDocumentCatalogCode(documentCatalogCode);
        queryAttach.setAttachmentTypeId(AttachmentTypeEnum.PAYMENT_PROOF.getCode());
        //获取附件信息
        List<CaseAttachmentInfoVo> paymentProofFileList = caseAppendixRecordService.getCaseAttachmentInfoList(queryAttach);
        paymentProofFileList.forEach(e -> notShowInOtherFileList.add(e.getId()));
        vo.setPaymentProofFileList(paymentProofFileList);
        queryAttach.setAttachmentTypeId(AttachmentTypeEnum.REAL_PLACE_CHECK_RECORD.getCode());
        List<CaseAttachmentInfoVo> realPlaceCheckRecordFileList = caseAppendixRecordService.getCaseAttachmentInfoList(queryAttach);
        realPlaceCheckRecordFileList.forEach(e -> notShowInOtherFileList.add(e.getId()));
        vo.setRealPlaceCheckRecordFileList(realPlaceCheckRecordFileList);
        queryAttach.setAttachmentTypeId("");
        List<CaseAttachmentInfoVo> otherFileListTmp = caseAppendixRecordService.getCaseAttachmentInfoList(queryAttach);
        List<CaseAttachmentInfoVo> otherFileList = new ArrayList<>();
        otherFileListTmp.forEach(e -> {
            if (!notShowInOtherFileList.contains(e.getId())) {
                otherFileList.add(e);
            }
        });
        vo.setOtherFileList(otherFileList);
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        vo.setHandleType(caseMainInfo.getHandleType());
        vo.setCasePartiesReasonType(caseMainInfo.getCasePartiesReasonType());
        return vo;
    }

    /**
     * 【V2.0.0】描述：重新构造执行情况文书内容
     *
     * @return {@link Result<String>} 操作结果
     * @author xiangyuyu
     * @date 2022-05-18 10:07
     */
    @Override
    public Result<String> refactorExecuteConditionDoc() {
        log.info("refactorExecuteConditionDoc start ...");
        /*
            重新组装:
            1.查询所有已手动生成执行情况记录的文书记录
            2.解析documentContent植入具体对象
            3.针对主办人、协办人姓名、主办人员执法证号、协办人员执法证号进行正确替换
            4.替换后重新更新
         */
        //执行情况记录-手动
        Example query = new Example(CaseDocumentRecord.class);
        query.createCriteria().andEqualTo("documentCatalogCode","ZXQKHCJL29F3F")
                //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
        List<CaseDocumentRecord> list = caseDocumentRecordMapper.selectByExample(query);

        Map<String,String> newContentParamInfo = new HashMap<>(20);

        if(!ObjectUtils.isEmpty(list) && list.size() > 0){
            list.forEach(e->{
                String id = e.getId();
                String caseId = e.getCaseId();
                String content = e.getDocumentContent();
                ExecuteConditionDocContentVo vo = new ExecuteConditionDocContentVo();
                vo.setId(id);
                //解析content
                if(!ObjectUtils.isEmpty(content)){
                    JSONObject jo = JSONObject.parseObject(content);
                    vo.setZXQKJL_DSR(jo.getString("ZXQKJL_DSR"));
                    vo.setZXQKJL_ZXWCRQ(jo.getString("ZXQKJL_ZXWCRQ"));
                    vo.setZXQKJL_ZXJCQK(jo.getString("ZXQKJL_ZXJCQK"));
                    vo.setZXQKJL_ZXFS(jo.getString("ZXQKJL_ZXFS"));
                    vo.setZXQKJL_JKPZ(jo.getJSONArray("ZXQKJL_JKPZ"));
                    vo.setZXQKJL_XCHCJL(jo.getJSONArray("ZXQKJL_XCHCJL"));
                    vo.setZXQKJL_ZBRYXM(jo.getString("ZXQKJL_ZBRYXM"));
                    vo.setZXQKJL_ZBRYZFZH(jo.getString("ZXQKJL_ZBRYZFZH"));
                    vo.setZXQKJL_XBRYXM(jo.getString("ZXQKJL_XBRYXM"));
                    vo.setZXQKJL_XBRYZFZH(jo.getString("ZXQKJL_XBRYZFZH"));
                    vo.setZXQKJL_BZ(jo.getString("ZXQKJL_BZ"));
                    vo.setDocumentNumber(jo.getString("documentNumber"));
                    vo.setAssistHandleSignPic(jo.getString("assistHandleSignPic"));
                    vo.setMainHandleSignPic(jo.getString("mainHandleSignPic"));
                    vo.setHandlePersonSignDate(jo.getString("handlePersonSignDate"));
                }
                //获取案件办案人员对应信息
                List<CaseHandlePersonRecord> handlers = caseHandlePersonRecordService.getCaseHandlePersonRecordList(caseId);
                CaseHandlePersonRecord mainHandleInfo = null;
                CaseHandlePersonRecord assistHandleInfo = null;
                if(!ObjectUtils.isEmpty(handlers)){
                    for (CaseHandlePersonRecord handler : handlers) {
                        String handlePersonType = handler.getHandlePersonType();
                        if(HandlePersonTypeEnum.MAIN.getCode().equals(handlePersonType)){
                            mainHandleInfo = handler;
                        } else {
                            assistHandleInfo = handler;
                        }
                    }
                } else {
                    log.warn("未匹配到办案人员记录信息,caseId:{}",caseId);
                }

                if(!ObjectUtils.isEmpty(mainHandleInfo)){
                    String mainHandleName = mainHandleInfo.getHandlePersonName();
                    if(!ObjectUtils.isEmpty(mainHandleName)){
                        //主办人姓名
                        vo.setZXQKJL_ZBRYXM(mainHandleName);
                    } else {
                        log.warn("主办人员姓名为空 caseId:{}",caseId);
                    }

                    String mainCert = mainHandleInfo.getLawEnforcementCert();
                    if(!ObjectUtils.isEmpty(mainCert)){
                        //主办人执法证号
                        vo.setZXQKJL_ZBRYZFZH(mainHandleInfo.getLawEnforcementCert());
                    } else {
                        log.warn("主办人员执法证号为空 caseId:{}",caseId);
                    }

                } else {
                    log.warn("无主办人员信息 caseId:{}",caseId);
                }

                if(!ObjectUtils.isEmpty(assistHandleInfo)){
                    String assistHandleName = assistHandleInfo.getHandlePersonName();
                    if(!ObjectUtils.isEmpty(assistHandleName)){
                        //协办人姓名
                        vo.setZXQKJL_XBRYXM(assistHandleName);
                    } else {
                        log.warn("协办人员姓名为空 caseId:{}",caseId);
                    }
                    String assistCert = assistHandleInfo.getLawEnforcementCert();
                    if(!ObjectUtils.isEmpty(assistCert)){
                        //协办人执法证号
                        vo.setZXQKJL_XBRYZFZH(assistHandleInfo.getLawEnforcementCert());
                    } else {
                        log.warn("协办人员执法证号为空 caseId:{}",caseId);
                    }

                } else {
                    log.warn("无协办人员信息 caseId:{}",caseId);
                }


                JSONObject json = (JSONObject) JSONObject.toJSON(vo);
                newContentParamInfo.put(id,json.toJSONString());
            });
        }
        //执行情况记录-自动
        query = new Example(CaseDocumentRecord.class);
        query.createCriteria().andEqualTo("documentCatalogCode","ZXQKHCJL7E422")
                //.andNotEqualTo("documentRecordStatus", DocumentRecordStatusEnum.WITHDRAW.getCode());
                .andIn("documentRecordStatus", Arrays.asList(DocumentRecordStatusEnum.NORMAL.getCode(), DocumentRecordStatusEnum.DRAFT.getCode()));
        list = caseDocumentRecordMapper.selectByExample(query);
        if(!ObjectUtils.isEmpty(list) && list.size() > 0){
            list.forEach(e->{
                String id = e.getId();
                String caseId = e.getCaseId();
                String content = e.getDocumentContent();
                ExecuteConditionDocContentAutoVo vo = new ExecuteConditionDocContentAutoVo();
                vo.setId(id);
                //解析content
                if(!ObjectUtils.isEmpty(content)){
                    JSONObject jo = JSONObject.parseObject(content);
                    vo.setZXQKJL_AUTO_DSR(jo.getString("ZXQKJL_AUTO_DSR"));
                    vo.setZXQKJL_AUTO_ZXWCRQ(jo.getString("ZXQKJL_AUTO_ZXWCRQ"));
                    vo.setZXQKJL_AUTO_ZXFS(jo.getString("ZXQKJL_AUTO_ZXFS"));
                    vo.setZXQKJL_AUTO_JKDH(jo.getString("ZXQKJL_AUTO_JKDH"));
                    vo.setZXQKJL_AUTO_JKRQ(jo.getString("ZXQKJL_AUTO_JKRQ"));
                    vo.setZXQKJL_AUTO_JKPZH(jo.getString("ZXQKJL_AUTO_JKPZH"));
                    vo.setZXQKJL_AUTO_JKPZJYM(jo.getString("ZXQKJL_AUTO_JKPZJYM"));
                    vo.setZXQKJL_AUTO_DSJG(jo.getString("ZXQKJL_AUTO_DSJG"));
                    vo.setZXQKJL_AUTO_ZFFS(jo.getString("ZXQKJL_AUTO_ZFFS"));
                    vo.setZXQKJL_AUTO_XMBM(jo.getString("ZXQKJL_AUTO_XMBM"));
                    vo.setZXQKJL_AUTO_XMMC(jo.getString("ZXQKJL_AUTO_XMMC"));
                    vo.setZXQKJL_AUTO_ZJMS_DW(jo.getString("ZXQKJL_AUTO_ZJMS_DW"));
                    vo.setZXQKJL_AUTO_ZJMS_SL(jo.getString("ZXQKJL_AUTO_ZJMS_SL"));
                    vo.setZXQKJL_AUTO_ZJMS_STANDARD(jo.getString("ZXQKJL_AUTO_ZJMS_STANDARD"));
                    vo.setZXQKJL_AUTO_ZJMS_JE(jo.getString("ZXQKJL_AUTO_ZJMS_JE"));
                    vo.setZXQKJL_AUTO_ZJMS_BZ(jo.getString("ZXQKJL_AUTO_ZJMS_BZ"));
                    vo.setZXQKJL_AUTO_ZJYJ(jo.getJSONArray("ZXQKJL_AUTO_ZJYJ"));
                    vo.setZXQKJL_AUTO_ZXJCQK(jo.getString("ZXQKJL_AUTO_ZXJCQK"));
                    vo.setZXQKJL_AUTO_ZBRYXM(jo.getString("ZXQKJL_AUTO_ZBRYXM"));
                    vo.setZXQKJL_AUTO_ZBRYZFZH(jo.getString("ZXQKJL_AUTO_ZBRYZFZH"));
                    vo.setZXQKJL_AUTO_XBRYXM(jo.getString("ZXQKJL_AUTO_XBRYXM"));
                    vo.setZXQKJL_AUTO_XBRYZFZH(jo.getString("ZXQKJL_AUTO_XBRYZFZH"));
                    vo.setZXQKJL_AUTO_BZ(jo.getString("ZXQKJL_AUTO_BZ"));

                    vo.setDocumentNumber(jo.getString("documentNumber"));
                    vo.setAssistHandleSignPic(jo.getString("assistHandleSignPic"));
                    vo.setMainHandleSignPic(jo.getString("mainHandleSignPic"));
                    vo.setHandlePersonSignDate(jo.getString("handlePersonSignDate"));
                }
                //获取案件办案人员对应信息
                List<CaseHandlePersonRecord> handlers = caseHandlePersonRecordService.getCaseHandlePersonRecordList(caseId);
                CaseHandlePersonRecord mainHandleInfo = null;
                CaseHandlePersonRecord assistHandleInfo = null;
                if(!ObjectUtils.isEmpty(handlers)){
                    for (CaseHandlePersonRecord handler : handlers) {
                        String handlePersonType = handler.getHandlePersonType();
                        if(HandlePersonTypeEnum.MAIN.getCode().equals(handlePersonType)){
                            mainHandleInfo = handler;
                        } else {
                            assistHandleInfo = handler;
                        }
                    }
                } else {
                    log.warn("未匹配到办案人员记录信息,caseId:{}",caseId);
                }

                if(!ObjectUtils.isEmpty(mainHandleInfo)){
                    String mainHandleName = mainHandleInfo.getHandlePersonName();
                    if(!ObjectUtils.isEmpty(mainHandleName)){
                        //主办人姓名
                        vo.setZXQKJL_AUTO_ZBRYXM(mainHandleName);
                    } else {
                        log.warn("主办人员姓名为空 caseId:{}",caseId);
                    }

                    String mainCert = mainHandleInfo.getLawEnforcementCert();
                    if(!ObjectUtils.isEmpty(mainCert)){
                        //主办人执法证号
                        vo.setZXQKJL_AUTO_ZBRYZFZH(mainHandleInfo.getLawEnforcementCert());
                    } else {
                        log.warn("主办人员执法证号为空 caseId:{}",caseId);
                    }

                } else {
                    log.warn("无主办人员信息 caseId:{}",caseId);
                }

                if(!ObjectUtils.isEmpty(assistHandleInfo)){
                    String assistHandleName = assistHandleInfo.getHandlePersonName();
                    if(!ObjectUtils.isEmpty(assistHandleName)){
                        //协办人姓名
                        vo.setZXQKJL_AUTO_XBRYXM(assistHandleName);
                    } else {
                        log.warn("协办人员姓名为空 caseId:{}",caseId);
                    }
                    String assistCert = assistHandleInfo.getLawEnforcementCert();
                    if(!ObjectUtils.isEmpty(assistCert)){
                        //协办人执法证号
                        vo.setZXQKJL_AUTO_XBRYZFZH(assistHandleInfo.getLawEnforcementCert());
                    } else {
                        log.warn("协办人员执法证号为空 caseId:{}",caseId);
                    }

                } else {
                    log.warn("无协办人员信息 caseId:{}",caseId);
                }


                JSONObject json = (JSONObject) JSONObject.toJSON(vo);
                newContentParamInfo.put(id,json.toJSONString());
            });
        }

        for (Map.Entry<String, String> entry : newContentParamInfo.entrySet()) {
            CaseDocumentRecord newRecord = new CaseDocumentRecord();
            newRecord.setId(entry.getKey());
            newRecord.setDocumentContent(entry.getValue());
            caseDocumentRecordMapper.updateByPrimaryKeySelective(newRecord);
        }
        log.info("refactorExecuteConditionDoc end");
        return Result.success(Constant.STRING_OPERATE_SUCCESS);
    }



    /**
     * 描述：执行流程滚动
     *
     * @param caseId              案件id
     * @param partyId             当事人id
     * @param documentCatalogCode 文书目录编码
     * @return Map<String, Object> 环节滚动信息
     * @author xiangyuyu
     * @date 2022-05-30 09:43
     */
    @Override
    @WorkFlowRollAnnotation
    @CaseChangeReportData
    public Map<String, Object> executeFlowRoll(String caseId, String partyId,String documentCatalogCode) {
        log.info("executeFlowRoll start...caseId:{},partyId:{}", caseId, partyId);
        Map<String, Object> map = new HashMap<>(8);
        if (ObjectUtils.isEmpty(caseId)) {
            throw new BusinessException("请指定案件id");
        }
        map.put("closeSignal", "CLOSE-TRIGGER-PUNISHEXCUTE-COMPLETE");
        if (!ObjectUtils.isEmpty(partyId)) {
            map.put("workSubId", partyId);
        }
        if(!ObjectUtils.isEmpty(documentCatalogCode)){
            map.put("documentCatalogCode", documentCatalogCode);
        }
        map.put("workId", caseId);
        map.put("success", "true");
        map.put("msg", "成功！");
        log.info("executeFlowRoll end...map:{}" + map);
        return map;
    }
}
